{% extends 'base/base.html' %}


{% block head %}
    <link rel="stylesheet" href="{{ url_for('static',filename='public/layui/css/layui.css') }}">
    <script src="{{ url_for('static', filename='public/layui/layui.js') }}"></script>

{% endblock %}

{% block page_title %}
    行情管理
{% endblock %}

{% block main_content %}
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>时间</th>
                <th>价格</th>
                <th>比上次增加</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        {% for i in market_list %}
            <tr data-name="{{ i.name }}" data-img="{{ i.market_img }}"
                data-priority="{{ i.priority }}" data-id="{{ i.id }}" data-price="{{ i.price }}" data-number="{{ i.number }}" data-rise="{{ i.rise }}" data-rice="{{ i.rise }}">
                <td>{{ i.create_time }}</td>
                <td>{{ i.price }}</td>
                <td>{{ i.price_add }}</td>
                <td>
                    <button class="btn btn-danger btn-xs delete-market-btn">删除</button>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    {% if pagination %}
        <div class="pagination-link" style="text-align: center">{{ pagination.links }}</div>
    {% endif %}


    <!-- Modal -->
    <div class="modal fade" id="market-dialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">产品</h4>
                </div>
                <div class="modal-body">
                    <form action="" class="form-horizontal" id="upload_form">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">名称：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="name" placeholder="名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片：</label>
                            <div class="col-sm-7">
                                <input type="text" class="form-control" name="market_img" placeholder="行情图片" id="upload_img">
                            </div>
                            <button type="button" class="layui-btn" id="upload_btn">上传图片</button>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-2 control-label">成交量：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="number" placeholder="成交量">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">价格：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="price" placeholder="价格">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">涨跌幅：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="rise" placeholder="涨跌幅">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">优先级：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="priority" placeholder="优先级">
                            </div>
                        </div>

                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="save-market-btn">保存</button>
                </div>
            </div>
        </div>
    </div>


<script>


layui.use('upload', function(){
    var upload = layui.upload;
    var dialog = $('#market-dialog');

    var linkInput = $("input[name='market_img']");
    //执行实例
    var uploadInst = upload.render({
        elem: '#upload_btn' //绑定元素
        ,url: '/cms/cms_upload/' //上传接口
        ,done: function(res){
             if(res.code == 200){
                 dialog.modal('show');
                 linkInput.val(res.data.url);
          }else {
                 layer.msg(res.message)
             }
        }
        ,error: function(){
          layer.msg('上传失败')
        }
    });
});

</script>

{% endblock %}
{% block script %}
    <script src="{{ url_for('static', filename='js/market.js') }}"></script>

{% endblock %}